#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e6 + 10;

int n;
struct Point
{
	int x, y;
	
	bool operator< (const Point &t)const
	{
		return y < t.y;
	}
}a[N];

int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i ++ )
	{
		int l, r;
		cin >> l >> r;
		
		a[i] = {l, r};
	}
	
	sort(a, a + n);
	
	int end = -1e9;
	int res = 0;
	
	for (int i = 0; i < n; i ++ )
	{
		if (end <= a[i].x)
		{
			res ++ ;
			end = a[i].y;
		}
	}
	
	cout << res << endl;
	
	return 0;
}
